package phone.example.com.a36kr.activity;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;
import phone.example.com.a36kr.R;
import phone.example.com.a36kr.bean.UserBean;
import phone.example.com.a36kr.other.mybmob.MyBmobUser;
import phone.example.com.a36kr.tools.BaseActivity;

/**
 * Created by dllo on 16/8/27.
 */
public class RegisterAllActivity extends BaseActivity implements View.OnClickListener {

    private EditText userName; // 用户名
    private EditText userPassword;//用户密码
    private EditText userPwEnter;//确认用户密码
    private Button registerOkBtn;//注册完成

    @Override
    protected int setLayout() {
        return R.layout.activity_all_register;
    }

    @Override
    protected void initView() {
        userName = bindView(R.id.register_all_user_name);
        userPassword = bindView(R.id.register_all_password);
        userPwEnter = bindView(R.id.register_all_password_enter);
        registerOkBtn = bindView(R.id.register_all_ok_btn);
        registerOkBtn.setOnClickListener(this);



    }

    @Override
    protected void initData() {





    }

    @Override
    public void onClick(View v) {
        //用户名
        String name = userName.getText().toString();
        //密码
        String password = userPassword.getText().toString();
        MyBmobUser bmobUser = new MyBmobUser();

        if (password.equals(userPwEnter.getText().toString())) {
            bmobUser.setUsername(name);
            bmobUser.setPassword(password);
        }else {
            Toast.makeText(this, "密码不一致", Toast.LENGTH_SHORT).show();
        }
        bmobUser.signUp(new SaveListener<MyBmobUser>() {

            @Override
            public void done(MyBmobUser myBmobUser, BmobException e) {
                if (e == null) {
                    Toast.makeText(RegisterAllActivity.this, "注册成功" , Toast.LENGTH_SHORT).show();
                    finish();
                } else {
                    Toast.makeText(RegisterAllActivity.this, "注册失败" , Toast.LENGTH_SHORT).show();
                    Log.d("注册", "e:" + e);
                }
            }
        });




//        if (password.equals(userPwEnter.getText().toString())){
//            UserBean userBean = new UserBean();
//            //获取用户名,密码,确认密码并set给bean
//            userBean.setName(userName.getText().toString());
//            userBean.setName(userName.getText().toString());
//            userBean.setPassword(userPassword.getText().toString());
//            userBean.save(new SaveListener<String>() {
//                @Override
//                public void done(String s, BmobException e) {
//                    if (e == null){
//                        Toast.makeText(RegisterAllActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
//                        finish();
//                    } else {
//                        Toast.makeText(RegisterAllActivity.this, "注册失败" + e.toString(), Toast.LENGTH_SHORT).show();
//                    }
//                }
//            });
//
//        }else {
//            Toast.makeText(this, "两次密码输入不一致,请检查密码", Toast.LENGTH_SHORT).show();
//        }



    }
}
